package tcu.iot.gasmanage.api;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import tcu.iot.gasmanage.common.Result;
import tcu.iot.gasmanage.common.utils.QuerySwitchUtils;
import tcu.iot.gasmanage.entity.export.ExportQuery;
import tcu.iot.gasmanage.service.ExportService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(value = "数据导出控制器")
@RestController
@ResponseBody
@RequestMapping("/export")
@CrossOrigin
public class ExportController {

    @Resource
    private ExportService exportService;

    @ApiOperation(value = "getExportOptions", notes = "获取导出筛选选项")
    @GetMapping(value = "/getExportOptions")
    public Result getExportOptions(){
        return exportService.getExportService();
    }

    @ApiOperation(value = "getList", notes = "获取导出筛选数据")
    @GetMapping(value = "/getList")
    public Result getList(HttpServletRequest request){
        ExportQuery exportQuery = JSON.parseObject(QuerySwitchUtils.QuerySwitch(request.getQueryString()),ExportQuery.class);
        return exportService.getList(exportQuery);
    }
}
